<?php

namespace App\Models;

/**
 * App\Models\Card
 *
 * @property int $id
 * @property int|null $category_id 分类id
 * @property string $card_question 问题
 * @property string $card_answer 答案
 * @property string $image_url 答案图片链接
 * @property int $status 卡片状态 0：正常 -1:逻辑删除
 * @property \Illuminate\Support\Carbon $created_at
 * @property \Illuminate\Support\Carbon $updated_at
 * @property-read \App\Models\Category|null $category
 * @property-read \App\Models\User $user
 * @method static \Illuminate\Database\Eloquent\Builder|Card newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|Card newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|Model orderCheck($request)
 * @method static \Illuminate\Database\Eloquent\Builder|Model pageCheck($request, $field = [], $makeVisible = [])
 * @method static \Illuminate\Database\Eloquent\Builder|Card query()
 * @method static \Illuminate\Database\Eloquent\Builder|Card whereCardAnswer($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Card whereCardQuestion($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Card whereCategoryId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Card whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Card whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Card whereImageUrl($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Card whereStatus($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Card whereUpdatedAt($value)
 * @mixin \Eloquent
 */
class Card extends Model
{
    protected $table = 'card';

    protected $primaryKey = 'id';

    protected $fillable = ['category_id', 'card_question', 'card_answer', 'image_url'];

    // 卡片状态
    const CARD_STATUS_NORMAL = 0; // 正常
    const CARD_STATUS_DELETE = -1; // 被删除


    /**
     * 模型关联
     */
    public function category()
    {
        return $this->belongsTo(Category::class,'category_id','id')->withDefault();
    }

    public function user()
    {
        return $this->belongsTo(User::class,'user_id','id');
    }
}
